package org.arch_learn.spring_cloud.sca_homework.service_code_8081.service;

import org.apache.dubbo.config.annotation.Service;
import org.arch_learn.spring_cloud.sca_homework.service_common_dependency.dubbo_api.ICodeDubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

@Service
public class CodeDubboService implements ICodeDubboService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public Integer validateCode(String email, String code) {
        Integer result;
        try {
            String realCode = stringRedisTemplate.opsForValue().get("verification:" + email);
            result = code.equals(realCode) ? 0 : 1;
        } catch (Exception e) {
            result = 2;
        }
        return result;
    }
}
